package com.ruoyi.framework.mybatisplus.util;

/**
 * @author yql
 * @describe UUIDGenerateValueUtils
 * @date 2023/3/13 17:39
 */

public class UUIDGenerateValueUtils extends ThreadLocal<String> {
    private static UUIDGenerateValueUtils util;

    static {
        util = new UUIDGenerateValueUtils();
    }

    public static UUIDGenerateValueUtils getInstance() {
        return util;
    }


    public static void append(String uuid) {
        getInstance().set(uuid);
    }

    public static String getUuid() {
        return getInstance().get();
    }

    public static void clear() {
        getInstance().remove();
    }

    @Override
    public String get() {
        String value = super.get();
        if (value == null) {
            throw new IllegalArgumentException("The current is not generated uuid");
        }
        remove();
        return value;
    }
}
